package com.shqcjd.preinstallmobile.ui.adapter;

import android.support.annotation.Nullable;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.EquipmentAbnormalBean;
import com.shqcjd.preinstallmobile.ui.activity.EquipmentAbnormalActivity;

import java.util.List;

public class EquipmentAbnormalItemAdapter extends BaseQuickAdapter<EquipmentAbnormalBean.EquipmentPartBean.EquipmentPartItemBean,BaseViewHolder> {
    private EquipmentAbnormalActivity context;
    private int epId;
    public EquipmentAbnormalItemAdapter(@Nullable List<EquipmentAbnormalBean.EquipmentPartBean.EquipmentPartItemBean> data, EquipmentAbnormalActivity context, int epId) {
        super(R.layout.item_equipment_abnormal_item, data);
        this.context = context;
        this.epId = epId;
    }

    @Override
    protected void convert(BaseViewHolder helper, EquipmentAbnormalBean.EquipmentPartBean.EquipmentPartItemBean item) {
        helper.setText(R.id.tv_item_equipment_abnormal_item_name, item.equipment_part_item_name);
        helper.setText(R.id.tv_item_equipment_abnormal_item_state, item.stand);
        helper.setText(R.id.tv_item_equipment_abnormal_item_last, "上一次结果\n"+item.last_check_info);
        RadioButton rb_item_equipment_abnormal_item_true = helper.getView(R.id.rb_item_equipment_abnormal_item_true);
        RadioButton rb_item_equipment_abnormal_item_false = helper.getView(R.id.rb_item_equipment_abnormal_item_false);
        if(item.last_check_info.equals("异常")){
            rb_item_equipment_abnormal_item_false.setChecked(true);
        }else{
            rb_item_equipment_abnormal_item_true.setChecked(true);
        }
        RadioGroup rg_item_equipment_abnormal_item = helper.getView(R.id.rg_item_equipment_abnormal_item);
        rg_item_equipment_abnormal_item.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId==R.id.rb_item_equipment_abnormal_item_true){
                    context.putCheckResultHttp(epId, "", 1, item.equipment_part_item_id);
                }else{
                    context.putCheckResultHttp(epId, "", -1, item.equipment_part_item_id);
                }
            }
        });
        context.radioGroupList.add(rg_item_equipment_abnormal_item);
    }

}
